package com.zhihu_lvliangi_android.option.zhengwu;

import com.zhihu_lvliangi_android.R;
import com.zhihu_lvliangi_android.R.id;
import com.zhihu_lvliangi_android.R.layout;
import com.zhihu_lvliangi_android.R.menu;
import com.zhihu_lvliangi_android.domain.ZhengwuColumnItem;
import com.zhihu_lvliangi_android.domain.ZhengwuGuideItem;
import com.zhihu_lvliangi_android.option.parent.ParentActivity;
import com.zhihu_lvliangi_android.service.MobileApplication;
import com.zhihu_lvliangi_android.util.Constant;
import com.zhihu_lvliangi_android.util.ViewHolder;

import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import android.util.Log;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

/**
 * 办事指南详情
 * @author 徐宇健
 *
 */
public class AffairDetailActivity extends ParentActivity {

	private ZhengwuGuideItem mData;
	private String[] mTitles;
	private LinearLayout container;
	private View parentView;
	private LayoutInflater inflater;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
	}

	@SuppressWarnings("deprecation")
	private void initActionBar() {
		ActionBar actionBar = getSupportActionBar();
		actionBar.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.homepage_actionbar_bg)));
		// 使自定义的普通View能在title栏显示, actionBar.setCustomView能起作用.
		actionBar.setIcon(new BitmapDrawable());
		actionBar.setDisplayHomeAsUpEnabled(true);//显示返回按钮
	}

	@Override
	protected int getLayoutId() {
		return R.layout.activity_affair_detail;
		
	}

	@Override
	protected void setupViews() {
	
		initActionBar();
		initView();
		
	}



	@Override
	protected void initialized() {
		
	}

	@Override
	protected void threadTask() {
		
	}
	
	private void initView() {
		 inflater = LayoutInflater.from(this);
		mData = (ZhengwuGuideItem) getIntent().getSerializableExtra(Constant.GENERAL_SAVE_KEY);
		container = (LinearLayout) findViewById(R.id.content_container);
		 mTitles = getResources().getStringArray(R.array.zhengwu_guideitem_title);
		 addView(0,mData.getGuide_name());//项目名称
		 addView(1,mData.getGuide_type_name());//项目类型
		 addView(2,mData.getApproval_department());//审批部门
		 addView(3,mData.getApproval_pprogeam());//审批程序
		 addView(4,mData.getDeclaration_materials());//申报材料
		 addView(5,mData.getTime_limit());//承若时限
		 addView(6,mData.getBasis_legal());//法规依据
		 addView(7,mData.getApplication_conditiions());//申请条件
		 addView(8,mData.getCharg());//收费标准
		 addView(9,mData.getAnnex_id());//附件下载
		 addView(10,mData.getFill_annex_id());//填表辅助
	}

	private void addView(int i, String src) {
		View v = inflater.inflate(R.layout.activity_affair_detail_item, null);
		TextView title = (TextView) v.findViewById(R.id.item_title);
		TextView content= (TextView) v.findViewById(R.id.item_content);
		title.setText(mTitles[i]);
		if (!TextUtils.isEmpty(src.trim())) {
			content.setText(src);
		}else {
			content.setText("暂无信息");
		}
		
		LayoutParams lp = new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
		container.addView(v,i, lp);;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			this.finish();
		default:
			return super.onOptionsItemSelected(item);
		}
	}

}
